<template>
	<view class="nearstore">
		<view class="head">
			<view class="sousuo clearfix">
				<view class="left fl clearfix" @click="showstatus = true">
					<view class="name fl">{{store_status}}</view>
					<image :src="baseUrl + '/wximage/dataxl.png'" class="fl"></image>
					<u-select v-model="showstatus" :list="sousuolist" @confirm="confirm"></u-select>
				</view>
				<view class="right fr">
					<input type="text" placeholder="请输入门店全称" v-model="keywords" @confirm="sousuo" />
					<image :src="baseUrl + '/wximage/index_sousuo.png'" @click="sousuo"></image>
				</view>
			</view>
		</view>
		<view class="content" v-if="list.length != 0">
			<view class="list clearfix" v-for="(item,index) in list" :key="index">
				<view class="left fl">
					<image :src="item.sitepicture"></image>
				</view>
				<view class="zhong fl">
					<view class="title">{{item.name}}</view>
					<view class="zhuangtai clearfix">
						<view v-if="item.systatus == 2">
							<image :src="baseUrl + '/wximage/index_you.png'"></image>
							<view class="desc">可租借</view>
						</view>
						<view v-else>
							<image :src="baseUrl + '/wximage/index_wu.png'"></image>
							<view class="desc">不可租借</view>
						</view>
						<view v-if="item.ghstatus == 2">
							<image :src="baseUrl + '/wximage/index_you.png'"></image>
							<view class="desc">可归还</view>
						</view>
						<view v-else>
							<image :src="baseUrl + '/wximage/index_wu.png'"></image>
							<view class="desc">不可归还</view>
						</view>
					</view>
					<view class="address">{{item.full_address}}</view>
				</view>
				<view class="dingwei clearfix" @click="daohang(index)">
					<view class="img fl">
						<image :src="baseUrl + '/wximage/index_weizhi.png'"></image>
					</view>
					<view class="juli fl">{{item.gongli}}km</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				keywords: '',
				store_status: '门店状态',
				store_value: 0,
				showstatus: false,
				sousuolist: [{
					value: '0',
					label: '所有',
				}, {
					value: '1',
					label: '可租借',
				}, {
					value: '2',
					label: '可归还',
				}, {
					value: '3',
					label: '可租借且可归还',
				}],
				longitude: '',
				latitude: '',
				list: [],
				page: 1,
				pageSize: 10,
				noData: false,
			}
		},
		onLoad() {
			this.latitude = uni.getStorageSync('latitude');
			this.longitude = uni.getStorageSync('longitude');
			
			this.getList(this.store_value,this.keywords,this.page,this.pageSize,this.latitude,this.longitude);
		},
		onReachBottom() {
			if(this.noData == false){
				this.page = this.page + 1;
				
				this.getList(this.store_value,this.keywords,this.page,this.pageSize,this.latitude,this.longitude);
			}
		},
		methods: {
			getList(store_value,keywords,page,pageSize,latitude,longitude){
				this.request({
					url: '/agent/stationlist',
					data: {
						keywords: keywords,
						store_value: store_value,
						page: page,
						pageSize: pageSize,
						lat: latitude,
						lng: longitude,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						let arr = res.data.data;
						for(let i=0;i<arr.length;i++){
							if(parseFloat(arr[i]['gongli']) > 500){
								arr[i]['gongli'] = '>500';
							}else{
								arr[i]['gongli'] = parseFloat(arr[i]['gongli']).toFixed(2);
							}
						}
						this.list = this.list.concat(arr);
					}else{
						this.noData = true;
					}
				})
			},
			confirm(e){
				if(e[0].value == 0){
					this.store_status = '门店状态';
					this.store_value = 0;
				}else{
					this.store_status = e[0].label.substring(0, 4);
					this.store_value = e[0].value;
				}
				
				this.page = 1;
				this.list = [];
				
				this.getList(this.store_value,this.keywords,this.page,this.pageSize,this.latitude,this.longitude);
			},
			sousuo(){
				this.page = 1;
				this.list = [];
				
				this.getList(this.store_value,this.keywords,this.page,this.pageSize,this.latitude,this.longitude);
			},
			daohang(index) {
				const latitude = Number(this.list[index].lat);
				const longitude = Number(this.list[index].lng);
				const name = this.list[index].name;
				const address = this.list[index].full_address;
				uni.getLocation({
					success(res) {
						uni.openLocation({
							name: name,
							address: address,
							latitude: latitude,
							longitude: longitude,
							scale: 15
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: #F8F8F8;
	}
	
	.nearstore {
		width: 100%;
		margin: 0 auto;
		
		.head {
			width: 100%;
			background: #ffffff;
			height: 80rpx;
			position: relative;

			.sousuo {
				width: 100%;
				padding: 8rpx 20rpx;
				box-sizing: border-box;

				.left {
					height: 64rpx;
					line-height: 64rpx;

					.name {
						color: #333333;
					}

					image {
						width: 44rpx;
						height: 44rpx;
						margin-top: 8rpx;
					}
				}

				.right {
					position: relative;

					// #ifdef MP-ALIPAY
					input {
						width: 500rpx;
						height: 54rpx;
						line-height: 54rpx;
						background: #F6F6F6;
						border-radius: 27rpx;
						padding-left: 32rpx;
						color: #999999;
					}
					
					//#endif
					
					// #ifdef MP-WEIXIN
					input {
						width: 500rpx;
						height: 64rpx;
						line-height: 64rpx;
						background: #F6F6F6;
						border-radius: 32rpx;
						padding-left: 32rpx;
						color: #999999;
					}
					//#endif

					image {
						width: 40rpx;
						height: 34rpx;
						position: absolute;
						right: 28rpx;
						top: 16rpx;
						z-index: 10;
					}
				}
			}
		}
		
		.content{
			width: 100%;
			padding: 20rpx;
			box-sizing: border-box;
			
			
			.list{
				width: 100%;
				padding: 20rpx 30rpx;
				box-sizing: border-box;
				background: #FFFFFF;
				border-radius: 6rpx;
				position: relative;
				margin-bottom: 20rpx;
				
				.left{
					margin-right: 30rpx;
				
					image{
						width: 140rpx;
						height: 140rpx;
						display: flex;
					}
				}
				
				.zhong{
					width: 50%;
					
					.title{
						font-size: 28rpx;
						color: #333333;
						margin-top: 10rpx;
					}
					
					.zhuangtai {
						margin-top: 4rpx;
						
						>view{
							display: inline-block;
						}
						
						image{
							width: 20rpx;
							height: 20rpx;
							display: inline-block;
						}
						
						.desc{
							display: inline-block;
							margin-left: 6rpx;
							margin-right: 20rpx;
							font-size: 24rpx;
							color: #333333;
						}
					}
					
					.address{
						font-size: 24rpx;
						color: #999999;
						margin-top: 10rpx;
						width: 100%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}
				
				.dingwei{
					position: absolute;
					bottom: 20rpx;
					right: 16rpx;
					width: 170rpx;
					height: 52rpx;
					line-height: 52rpx;
					border: 1rpx solid #333333;
					border-radius: 28rpx;
					
					.img{
						margin-left: 16rpx;
						margin-right: 4rpx;
						
						image{
							width: 24rpx;
							height: 24rpx;
						}
					}
					
					.juli{
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}
		
		.empty {
			width: 100%;
			margin: 200rpx auto 0;
			text-align: center;
		
			image {
				width: 390rpx;
				height: 340rpx;
			}
		
			text {
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>